package cn.com.starbucks.activity.controller;

import cn.com.starbucks.activity.bean.dto.TestDTO;
import cn.com.starbucks.activity.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 *
 * @author tecsmile@outlook.com
 * @version 1.0
 * @date 2021/4/13 4:32 下午
 **/

@RefreshScope
@RestController
public class TestController {
    @Value("${spring.test}")
    private String confStr;

    private TestService testService;

    @Autowired
    public void setTestService(TestService testService) {
        this.testService = testService;
    }

    @GetMapping("test")
    public Map<String, String> testConfigMap() {
        Map<String, String> testConfig = new HashMap<>(1);
        testConfig.put("test", confStr);
        return testConfig;
    }

    @GetMapping("/test/detail")
    public TestDTO test2(@RequestParam Long id) {
        return testService.detail(id);
    }

    @GetMapping("/test/redis")
    public String test3(@RequestParam String key) {
        return testService.redisVal(key);
    }

}
